package net.tools.web;

import java.io.*;

class TunnelResponse extends TunnelSerializable
{

	static final byte SUCCESS = 0;

	static final byte FAIL = 1;

	private byte status;

	byte getStatus()
	{
		return status;
	}

	void setStatus(byte status)
	{
		this.status = status;
	}

	void writeBodyTo(DataOutputStream out) throws IOException
	{
		out.writeLong(getSeq());
		out.writeByte(status);
		if(getCmd() == TunnelCommand.RECEIVE && getStatus() == SUCCESS)
		{
			out.writeInt(getLen());
			out.write(getData(), 0, getLen());
		}
	}

	void readBodyFrom(DataInputStream in) throws IOException
	{
		setSeq(in.readLong());
		setStatus(in.readByte());
		if(getCmd() == TunnelCommand.RECEIVE && getStatus() == SUCCESS)
		{
			setLen(in.readInt());
			in.readFully(getData(), 0, getLen());
		}
	}

}
